<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--    <el-form-item label="流水号" prop="commissionNo">-->
<!--      <el-input v-model="dataForm.commissionNo" placeholder="流水号"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="员工ID" prop="staffId">-->
<!--      <el-input v-model="dataForm.staffId" placeholder="员工ID"></el-input>-->
<!--    </el-form-item>-->
    <el-form-item label="提成类型" prop="commissionTypeId">
      <el-input v-model="dataForm.commissionTypeId" placeholder="提成类型"></el-input>
    </el-form-item>
    <el-form-item label="会员" prop="memberId">
      <el-input v-model="dataForm.memberId" placeholder="会员"></el-input>
    </el-form-item>
    <el-form-item label="销售金额" prop="saleMoney">
      <el-input v-model="dataForm.saleMoney" placeholder="销售金额"></el-input>
    </el-form-item>
    <el-form-item label="提成金额" prop="commissionMoney">
      <el-input v-model="dataForm.commissionMoney" placeholder="提成金额"></el-input>
    </el-form-item>
    <el-form-item label="租户" prop="sellerId">
      <el-input v-model="dataForm.sellerId" placeholder="租户"></el-input>
    </el-form-item>
    <el-form-item label="销售时间" prop="saleTime">
      <el-input v-model="dataForm.saleTime" placeholder="销售时间"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :disabled="disabledSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
				disabledSubmit:false,
        dataForm: {
          id: 0,
          commissionNo: '',
          staffId: '',
          commissionTypeId: '',
          memberId: '',
          saleMoney: '',
          commissionMoney: '',
          sellerId: '',
          saleTime: '',
          remark: ''
        },
        dataRule: {
          commissionNo: [
            { required: true, message: '流水号不能为空', trigger: 'blur' }
          ],
          staffId: [
            { required: true, message: '员工ID不能为空', trigger: 'blur' }
          ],
          commissionTypeId: [
            { required: true, message: '提成类型不能为空', trigger: 'blur' }
          ],
          memberId: [
            { required: true, message: '会员不能为空', trigger: 'blur' }
          ],
          saleMoney: [
            { required: true, message: '销售金额不能为空', trigger: 'blur' }
          ],
          commissionMoney: [
            { required: true, message: '提成金额不能为空', trigger: 'blur' }
          ],
          sellerId: [
            { required: true, message: '租户不能为空', trigger: 'blur' }
          ],
          saleTime: [
            { required: true, message: '销售时间不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/member/tstorestaffcommissionrecord/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.commissionNo = data.tStoreStaffCommissionRecord.commissionNo
                this.dataForm.staffId = data.tStoreStaffCommissionRecord.staffId
                this.dataForm.commissionTypeId = data.tStoreStaffCommissionRecord.commissionTypeId
                this.dataForm.memberId = data.tStoreStaffCommissionRecord.memberId
                this.dataForm.saleMoney = data.tStoreStaffCommissionRecord.saleMoney
                this.dataForm.commissionMoney = data.tStoreStaffCommissionRecord.commissionMoney
                this.dataForm.sellerId = data.tStoreStaffCommissionRecord.sellerId
                this.dataForm.saleTime = data.tStoreStaffCommissionRecord.saleTime
                this.dataForm.remark = data.tStoreStaffCommissionRecord.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
				this.disabledSubmit = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/member/tstorestaffcommissionrecord/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'commissionNo': this.dataForm.commissionNo,
                'staffId': this.dataForm.staffId,
                'commissionTypeId': this.dataForm.commissionTypeId,
                'memberId': this.dataForm.memberId,
                'saleMoney': this.dataForm.saleMoney,
                'commissionMoney': this.dataForm.commissionMoney,
                'sellerId': this.dataForm.sellerId,
                'saleTime': this.dataForm.saleTime,
                'remark': this.dataForm.remark
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
										this.disabledSubmit = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
